import { QueryClient, useMutation } from "@tanstack/react-query";
import { useForm } from "react-hook-form";
import { userControllerSetRole } from "@/shared/api/api.user";
import { AxiosError } from "axios";
import { TestService } from "@/shared/api/api.test";
import { CreateTestDTO } from "@/shared/interfaces";


export function useCreateTest() {
    const queryClient = new QueryClient

    const createTestMutation = useMutation(
        {
            mutationFn: TestService.create,
            onError: (error: (AxiosError<{ message: string }>)) => error,
        }, queryClient
    );
    const errorMessage = createTestMutation.error?.response?.data.message

    return {
        errorMessage,
        isSuccess: createTestMutation.isSuccess,
        response: createTestMutation.data,
        handleMutate: (dto: CreateTestDTO) => {
            createTestMutation.mutate(dto)
        }
    };
}